package com.itheima.stock.config;

import com.itheima.stock.properties.StockJobProperties;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zxh
 * @created 2024/12/23 20:45
 * @description
 *  任务调度器配置
 */
@Slf4j
@Configuration
public class ExecutorConfiguration {
    @Autowired
    private StockJobProperties properties;


    /**
     * 执行器配置到容器
     * @return
     */
    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> stock-job 配置初始化开始.");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(properties.getAdminAddress());
        xxlJobSpringExecutor.setAppname( properties.getAppName());
        xxlJobSpringExecutor.setAddress( properties.getExecutorAddress());
        xxlJobSpringExecutor.setIp( properties.getExecutorIp());
        xxlJobSpringExecutor.setPort( properties.getExecutorPort());
        xxlJobSpringExecutor.setAccessToken( properties.getAccessToken());
        xxlJobSpringExecutor.setLogPath( properties.getExecutorLogPath());
        xxlJobSpringExecutor.setLogRetentionDays( properties.getExecutorRetentionDays());

        return xxlJobSpringExecutor;
    }
}
